package com.bytedance.frameworks.core.thread;

import java.util.concurrent.Executor;
import java.util.concurrent.PriorityBlockingQueue;

public abstract class AsyncTask {
    private static volatile Executor a;

    static {
        new PriorityBlockingQueue();
        a = new a((byte) 0);
    }

    public enum Status {
        PENDING,
        RUNNING,
        FINISHED
    }

    static final class a implements Executor {
        private PriorityBlockingQueue a;
        private PriorityBlockingQueue b;
        private e c;
        private e d;

        a(byte arg1) {
            this();
        }

        private a() {
            this.a = new PriorityBlockingQueue();
            this.b = new PriorityBlockingQueue();
        }

        protected synchronized final void a(TTPriority$ThreadType arg3) {
            Object v0_1;
            if (arg3 != null) {
                if (arg3.getValue() == TTPriority$ThreadType.API.getValue()) {
                    v0_1 = this.b.poll();
                    this.d = ((e) v0_1);
                    if (v0_1 != null) {
                        com.bytedance.frameworks.core.thread.c.a();
                        com.bytedance.frameworks.core.thread.c.a(this.d);
                    }
                }
            }

            v0_1 = this.a.poll();
            this.c = ((e) v0_1);
            if (v0_1 != null) {
                com.bytedance.frameworks.core.thread.c.a();
                com.bytedance.frameworks.core.thread.c.b(this.c);
            }
        }

        public synchronized final void execute(Runnable arg5) {
            TTPriority$Priority v1_1;
            TTPriority$ThreadType v1;
            TTPriority$Priority v2;
            TTPriority$ThreadType v0 = null;
            v2 = TTPriority$Priority.NORMAL;
            v1 = TTPriority$ThreadType.DEFAULT;
            if (arg5 == null) {
                v0 = v1;
                v1_1 = v2;
            } else if ((arg5 instanceof d)) {
                v1_1 = null;
            } else {
                v0 = v1;
                v1_1 = v2;
            }

            if (v0 == null || v0.getValue() != TTPriority$ThreadType.API.getValue()) {
                this.a.offer(new b(this, v1_1, arg5));
                if (this.c == null) {
                    this.a(TTPriority$ThreadType.DEFAULT);
                }
            } else {
                this.b.offer(new com.bytedance.frameworks.core.thread.a(this, v1_1, arg5));
                if (this.d == null) {
                    this.a(TTPriority$ThreadType.API);
                }
            }
        }
    }
}

